<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
    <crudOperation :permission="permission">
      <!-- <el-button
              slot="right"
              class="filter-item"
              size="mini"
              type="danger"
              icon="el-icon-remove-outline"
              :loading="enable"
              @click="crud.enableOrDisable('DISABLE')"
              :disabled="crud.selections.length < 1"
              v-permission="permission.disable"
      >
        禁用
      </el-button>
      <el-button
              slot="right"
              class="filter-item"
              size="mini"
              type="success"
              icon="el-icon-circle-check"
              :loading="able"
              :disabled="crud.selections.length < 1"
              @click="crud.enableOrDisable('ENABLE')"
              v-permission="permission.enable"
      >
        启用
      </el-button> -->
    </crudOperation>
      <!-- <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="70px">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户名称">
                <el-input></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="销售部门">
                <el-input></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="销售人员">
                <el-input></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户分类">
                <el-input></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户区域">
                <el-input></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div> -->
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="800px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">

          <el-form-item label="渠道编码">
            <el-input v-model="form.code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="渠道名称">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="渠道链接">
            <el-input v-model="form.link" style="width: 370px;" />
          </el-form-item>
          <el-row :gutter="24" >
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="渠道价格参数X1">
              <el-input v-model="form.channelPriceX1" style="width: 120px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
            <el-form-item label="渠道价格参数Y1">
              <el-input v-model="form.channelPriceY1" style="width: 120px;" />
            </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
            <el-form-item label="渠道价格参数Z1">
              <el-input v-model="form.channelPriceZ1" style="width: 120px;" />
            </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24" >
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="渠道价格参数X2">
                <el-input v-model="form.channelPriceX2" style="width: 120px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="渠道价格参数Y2">
                <el-input v-model="form.channelPriceY2" style="width: 120px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="渠道价格参数Z2">
                <el-input v-model="form.channelPriceZ2" style="width: 120px;" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24" >
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="渠道价格参数X3">
                <el-input v-model="form.channelPriceX3" style="width: 120px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="渠道价格参数Y3">
                <el-input v-model="form.channelPriceY3" style="width: 120px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="渠道价格参数Z3">
                <el-input v-model="form.channelPriceZ3" style="width: 120px;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="渠道负责人">
            <zSelect :multiple="true" :value.sync="form.userIds" :showName="form.userName" :label="form.userName" url="api/dropDown/sysUserList"/>

          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <right-click-menu @tableConfig="tableConfig" :options.sync="rightClickMenuConfig"></right-click-menu>
      <el-dialog title="表格配置"
               :visible.sync="tableConfigShow"
               width="60%">
      <j-table-column-config :columns.sync="currentHeader"  @tabSave="saveHead"/>
    </el-dialog>
      <el-table ref="table" stripe border v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler" @row-dblclick="crud.toEdit($event)" @header-dragend="changeColWidth"  v-draghead="manyTableOption" :cell-style="{'text-align':'center'}">
        <el-table-column :render-header="crud.renderHeader" fixed type="selection" width="55" />
        <el-table-column :render-header="crud.renderHeader" fixed type="index" width="55" label="序号"/>
        <!-- <el-table-column v-if="columns.visible('code')" prop="code" label="渠道编码" width="100"/>
        <el-table-column v-if="columns.visible('name')" prop="name" label="渠道名称" width="100"/>
        <el-table-column v-if="columns.visible('link')" prop="link" label="渠道链接" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceX1')" prop="channelPriceX1" label="渠道价格参数X1" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceY1')" prop="channelPriceY1" label="渠道价格参数Y1" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceZ1')" prop="channelPriceZ1" label="渠道价格参数Z1" width="100" />
        <el-table-column v-if="columns.visible('channelPriceX2')" prop="channelPriceX2" label="渠道价格参数X2" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceY2')" prop="channelPriceY2" label="渠道价格参数Y2" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceZ2')" prop="channelPriceZ2" label="渠道价格参数Z2" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceX3')" prop="channelPriceX3" label="渠道价格参数X3" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceY3')" prop="channelPriceY3" label="渠道价格参数Y3" width="100"/>
        <el-table-column v-if="columns.visible('channelPriceZ3')" prop="channelPriceZ3" label="渠道价格参数Z3" width="100"/>
        <el-table-column v-if="columns.visible('status')" prop="status" label="状态" width="100">
          <template slot-scope="scope">
           <span>{{ dict.label.common_status[scope.row.status] }}</span>
         </template>
        </el-table-column> -->
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
          :fixed="item.fixed"
          :sortable="item.sortable?'custom':false"
          :sort-orders="['descending', 'ascending', null]"
          sort-change="sort"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template >
              <span :class="{'blue':(scope.row['orderStatus']==='INVALID')}" v-if="item.type == 1" style="margin-left: 0px">
                  <span :class="{'red':(scope.row[`type`] === 2),'blue':(item.orderStatus==='INVALID')}">
                    {{scope.row[`${item.prop}`]}}
                  </span>
              </span>
              <span :class="{'blue':(scope.row['orderStatus']==='INVALID')}" v-else-if="item.type == 2" style="margin-left: 0px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span :class="{'blue':(scope.row['orderStatus']==='INVALID')}" v-else-if="item.type == 3" style="margin-left: 0px">
                <span :class="{'red':(scope.row[`type`] === 2)}">
                  {{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}
                </span>
              </span>
            </template>
          </template>
        </el-table-column>
        <!-- <el-table-column v-permission="['admin','jstChannel:edit','jstChannel:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudJstChannel from '@/api/erp/jstChannel'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import{manyTableMixin}from"../../../mixins/manyTableMixin";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
// crud交由presenter持有
const defaultCrud = CRUD({ title: '渠道档案', url: 'api/jstChannel', sort: 'id,asc', crudMethod: { ...crudJstChannel },optShow: {
    add: true,
    edit: true,
    enable: true,
    disable: true,
  },})
const defaultForm = { id: null, code: null, name: null, type: null, link: null, userId: null,userIds:null, mainColor: null, photoTime: null, groundNewTime: null, roundingRule: null, goodsCostPrice1: null, goodsCostPrice2: null, goodsCostPrice3: null, channelPriceX1: null, channelPriceY1: null,channelPriceZ1:null, channelPrice1: null, channelPriceX2: null, channelPriceY2: null,channelPriceZ2:null, channelPrice2: null, channelPriceX3: null, channelPriceY3: null, channelPriceZ3:null,channelPrice3: null, buyerShowPlan: null, buyerShowComplete: null, oldCustomerPlan: null, oldCustomerComplete: null, seq: null, status: null, remark: null, createUserId: null, createTime: null, updateUserId: null, updateTime: null }
export default {
  name: 'JstChannel',
  dicts:['common_status'],
  components: { pagination, crudOperation, rrOperation, udOperation ,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),manyTableMixin],
  data() {
    return {

      permission: {
        add: ['admin', 'jstChannel:add'],
        edit: ['admin', 'jstChannel:edit'],
        del: ['admin', 'jstChannel:del'],
        import: ['admin', 'jstChannel:import'],
        export: ['admin', 'jstChannel:export'],
        copy: ['admin', 'jstChannel:copy'],
        upload: ['admin', 'jstChannel:upload'],
        download: ['admin', 'jstChannel:download'],
        enable: ['admin', 'jstChannel:enable'],
        disable: ['admin', 'jstChannel:disable'],
      },
      rules: {
      },
      extendRightEvent:[
        {
          fnHandler: 'delDetail', // 绑定事件
          icoName: 'el-icon-delete', // icon图标
          btnName: '删除' // 菜单名称
        },
      ],   }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
